<template>
  <div class="container mine">

  </div>
</template>

<script>
export default {
  name: 'empty',
  data() {
    return {
      UserNumber:'',
      name:'--',
      integral:'--',
      HeadUrl:'',
      code:'',
      OpenId:'',
      userType:'',
      companyUserInfo:'',
    }
  },
  mounted() {
    this.code = this.getUrlParam('code');
    this.userType = localStorage.getItem("userType");
    console.log('code:' + this.code)
    this.getComWeiXinInfo();
  },
  methods: {
    toPage(url){
      this.$router.push({name: url})
    },
    getComWeiXinInfo(){
      this.$api.mine.getComWeiXinInfo({   
          code: this.code,
          userType: this.userType
      }).then(res=> {
        console.log(res);
        console.log('openid:'+res.Data.openid);
        let data = res.Data;
        if(res.Data.isRegister){
          this.$router.push({
            path: '/mine'
          })
        }else{
          this.$router.push({
            path: '/shopRegistered',
            query:{openId:data.wXOAuthUserInfo.openid}
          })
        }
        localStorage.setItem("isFirst",'false');
        this.login()
      })    
    },
    getCompanyUserInfo(){
      this.$api.mine.getCompanyUserInfo().then(res=> {
        if(res.IsSuccess){
          this.companyUserInfo = res.Data;
          this.HeadUrl = res.Data.HeadUrl;
          localStorage.setItem("userInfo", JSON.stringify(res.Data));
        }
      })    
    },
    logout(){
      this.$dialog.confirm({
        title: '提示',
        message: '是否退出登录'
      }).then(() => {
        // on confirm
        localStorage.removeItem("authorization");
        this.$router.push({
          path: '/login',
          query:{userType:this.userType}
      })
      }).catch(() => {
        // on cancel
      });
    },
    getUrlParam(name){  
      //构造一个含有目标参数的正则表达式对象  
      var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");  
      //匹配目标参数  
      var r = window.location.search.substr(1).match(reg);  
      //返回参数值  
      if (r!=null) return unescape(r[2]);  
      return null;  
    },
    login(){
      this.$api.login.userLogin({   
          OpenId: this.OpenId,
          UserType:0  
      }).then(res=> {
        if(res.IsSuccess){
          localStorage.setItem("authorization",res.Data);
          this.getUserInfo();
        }
      })    
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
</style>